package com.wzl.factory.controller;

import com.wzl.common.DpPublicRequest;
import com.wzl.common.DpPublicResponse;
import com.wzl.common.DpUserEntity;
import com.wzl.common.constant.DpPublicConstants;
import com.wzl.factory.abstractFactory.FactoryBM320;
import com.wzl.factory.abstractFactory.FactoryBM325;
import com.wzl.factory.easyFactoty.Factory;
import com.wzl.factory.factoryMethod.FactoryBMW320;
import com.wzl.factory.factoryMethod.FactoryBMW325;
import com.wzl.factory.service.DpfatoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @description:
 * @author: weizhongli
 * @create: 2022-08-27 15:40
 */
@Controller
public class DpfatoryController {

    @Autowired
    private DpfatoryService dpfatoryService;

    @RequestMapping("test")
    @ResponseBody
    public DpPublicResponse testQuery(DpPublicRequest dpPublicRequest) {

        List<DpUserEntity> dpUserEntities = dpfatoryService.testQuery(dpPublicRequest);

        DpPublicResponse dpPublicResponse = new DpPublicResponse(DpPublicConstants.SUCCESS_CODE, DpPublicConstants.SUCCESS_MESSAGE, dpUserEntities);
        return dpPublicResponse;
    }

    /**
     * 简单工厂
     */
    @RequestMapping("easyFactory/{type}")
    @ResponseBody
    public DpPublicResponse easyFactory(@PathVariable("type") int type) {

        Factory factory = new Factory();
        Object bmw = factory.createBMW(type);

        DpPublicResponse dpPublicResponse = new DpPublicResponse(DpPublicConstants.SUCCESS_CODE, DpPublicConstants.SUCCESS_MESSAGE, bmw);
        return dpPublicResponse;
    }


    /**
     * 工厂方法
     */
    @RequestMapping("factoryMethod/{type}")
    @ResponseBody
    public DpPublicResponse factoryMethod(@PathVariable("type") int type) {

        if (type == 320) {
            FactoryBMW320 factoryBMW320 = new FactoryBMW320();
            Object bmw = factoryBMW320.createBMW();
            return new DpPublicResponse(DpPublicConstants.SUCCESS_CODE, DpPublicConstants.SUCCESS_MESSAGE, bmw);
        } else {
            FactoryBMW325 factoryBMW325 = new FactoryBMW325();
            Object bmw = factoryBMW325.createBMW();
            return new DpPublicResponse(DpPublicConstants.SUCCESS_CODE, DpPublicConstants.SUCCESS_MESSAGE, bmw);

        }
    }

    /**
     * 抽象方法
     */
    @RequestMapping("abstractFactory/{type}")
    @ResponseBody
    public DpPublicResponse abstractFactory(@PathVariable("type") int type) {

        if (type == 320) {
            //生产宝马320系列配件
            FactoryBM320 factoryBM320 = new FactoryBM320();
            factoryBM320.createEngine();
            factoryBM320.createAircondition();
            String s = factoryBM320.toString();
            return new DpPublicResponse(DpPublicConstants.SUCCESS_CODE, DpPublicConstants.SUCCESS_MESSAGE, s);

        } else {
            //生产宝马523系列配件
            FactoryBM325 factoryBM325 = new FactoryBM325();
            factoryBM325.createEngine();
            factoryBM325.createAircondition();
            String s = factoryBM325.toString();
            return new DpPublicResponse(DpPublicConstants.SUCCESS_CODE, DpPublicConstants.SUCCESS_MESSAGE, s);
        }
    }
}